package com.se.dao.mysql;

import com.se.domain.mysql.ActivityDO;
import com.se.domain.mysql.CategoryDO;
import com.se.domain.request.param.CreateActParam;
import com.se.domain.vo.CatVO;
import com.se.mapper.CatMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.*;

@Repository
public class CatDao {
    @Autowired
    CatMapper catMapper;

    public List<CategoryDO> listAll() {
        return catMapper.listAll();
    }

    public List<CategoryDO> listByCatIds(List<Long> catIds) {
        if(catIds.isEmpty()){
            return new LinkedList<>();
        }
        return catMapper.listByCatIds(catIds);
    }

    public Map<Long, CategoryDO> mapByCatIds(Collection<Long> catIds) {
        if(catIds.isEmpty()){
            return new TreeMap<>();
        }
        List<CategoryDO> doList = catMapper.listByCatIds(catIds);

        Map<Long, CategoryDO> map = new HashMap<>();
        for (CategoryDO categoryDO : doList) {
            map.put(categoryDO.getCatId(), categoryDO);
        }
        return map;
    }

    public Map<Long, CatVO> mapVOByCatIds(Collection<Long> catIds) {
        if(catIds.isEmpty()){
            return new TreeMap<>();
        }
        List<CategoryDO> doList = catMapper.listByCatIds(catIds);

        Map<Long, CatVO> map = new HashMap<>();
        for (CategoryDO categoryDO : doList) {
            map.put(categoryDO.getCatId(), new CatVO(categoryDO));
        }
        return map;
    }
}
